package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.SysLoginInfo;
import io.mybatis.example.springboot.service.SysLoginInfoService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * sys_login_info - 系统访问记录
 *
 * @author mkj
 */
@RestController
@RequestMapping("sysLoginInfoes")
public class SysLoginInfoController {

  @Autowired
  private SysLoginInfoService sysLoginInfoService;

  @PostMapping
  public DataResponse<SysLoginInfoDO> save(@RequestBody SysLoginInfoDO sysLoginInfo) {
    return DataResponse.ok(sysLoginInfoService.save( sysLoginInfo));
  }

  @GetMapping
  public RowsResponse<SysLoginInfoDO> findList(@RequestBody SysLoginInfoDO sysLoginInfo) {
    return RowsResponse.ok(sysLoginInfoService.findList( sysLoginInfo));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<SysLoginInfoDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysLoginInfoService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<SysLoginInfoDO> update(@PathVariable("id") Long id, @RequestBody SysLoginInfoDO sysLoginInfo) {
    sysLoginInfo.setId(id);
    return DataResponse.ok(sysLoginInfoService.update( sysLoginInfo));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(sysLoginInfoService.deleteById(id) == 1);
  }

}
